package com.thoughtworks;

/**
 * Created by daisyshih on 2014-09-13.
 */


public class Diamond {

    public static void printLineSpace(int n) {
        for (int i = 0; i < n; i++) {
            System.out.print(" ");
        }

    }

    public static int nthOddNumber(int n) {
        return n + (n - 1);
    }
/*
Isosceles Triangle
Given a number n, print a centered triangle. Example for n=3:
  *
 ***
*****
 */

    public static void printIsoTri(int n) {
        int s = 1;
        n--;
        while (n >= 0) {
            printLineSpace(n);
            Triangle.printLineAsterisk(nthOddNumber(s));
            System.out.println();
            n--;
            s++;

        }

    }

    public static void printUpSideDownIsoTri(int n) {
        int s = 1;
        n--;
        while (n >= 0) {
            printLineSpace(s);
            Triangle.printLineAsterisk(nthOddNumber(n));
            System.out.println();
            n--;
            s++;

        }

    }

    /**
     * Diamond
     * Given a number n, print a centered diamond. Example for n=3:
     * <p/>
     * <p/>
     * **
     * ****
     * **
     *
     * @param n size of diamond
     */

    public static void printDiamond(int n) {
        printIsoTri(n);
        printUpSideDownIsoTri(n);


    }

    /**
     * Diamond with Name
     * Given a number n, print a centered diamond with your name in place of the middle line. Example for n=3:
     * <p/>
     * <p/>
     * **
     * Bill
     * **
     *
     * @param name String for name, n size of diamond
     */

    public static void printDiamondWithName(int size, String name) {
        int s = 1;
        int n = size;
        n--;
        while (n >= 0) {
            if (n == 0) {
                System.out.print(name);
                break;
            } else {

                printLineSpace(n);
                Triangle.printLineAsterisk(nthOddNumber(s));
                System.out.println();
                n--;
                s++;

            }

        }
        System.out.println();
        printUpSideDownIsoTri(size);


    }

    public static void main(String[] args) {
        printIsoTri(3);
        System.out.println();
        printDiamond(3);
        System.out.println();
        printDiamondWithName(3, "Bill");
    }
}
